                                                                                      

clear all
set more off

*********************************************************
*install necessary packages
**********************************************************
*ssc install estout, replace
*ssc install psmatch2


********************
* Pre-process data *
********************
*import institutions
use "other_raw_data/institutional_indices.dta", clear
keep country_name year v2x_jucon v2xel_frefair v2xme_altinf
rename country_name CountryName
save "other_raw_data/institutions.dta", replace
*Merge with macro_indicators
joinby CountryName year using "other_raw_data/macro_indicators.dta"
order v2xel_frefair v2x_jucon v2xme_altinf, after(CountryCode)
rename ( CountryName v2xel_frefair v2x_jucon v2xme_altinf ) (countryname media election judicial)
*PCA Analysis to create institutions index
pca judicial election media
predict institutions
rename Inflation inflation

save "other_raw_data/institutions_macro_merge.dta", replace


use "manifestos/distance_data.dta", clear


****************************************************
*Merge Data with Macro and Institutional indicators *
****************************************************

joinby countryname year using "other_raw_data/institutions_macro_merge.dta"


**** create indicators for treated elections (based on Funke et al.'s (2023) database)
gen pop_temp = 0
gen pop_temp_left = 0
gen pop_temp_right = 0

* Kirchner 2003-2007
replace pop_temp_left = 1 if date == "200710" & countryname == "Argentina"
* Fernandez 2007-2015
replace pop_temp_left = 1 if date == "200906" & countryname == "Argentina"
replace pop_temp_left = 1 if date == "201110" & countryname == "Argentina"
replace pop_temp_left = 1 if date == "201310" & countryname == "Argentina"
replace pop_temp_left = 1 if date == "201510" & countryname == "Argentina"
* Morales 2006-2018
replace pop_temp_left = 1 if date == "200912" & countryname == "Bolivia"
replace pop_temp_left = 1 if date == "201410" & countryname == "Bolivia"
* Correa 2007-2017
replace pop_temp_left = 1 if date == "200904" & countryname == "Ecuador"
replace pop_temp_left = 1 if date == "201302" & countryname == "Ecuador"
replace pop_temp_left = 1 if date == "201702" & countryname == "Ecuador"
* Tsipras 2015-2018
replace pop_temp_left = 1 if date == "201509" & countryname == "Greece"
* Fico 2006-2010; 2012-2018
replace pop_temp_left = 1 if date == "201006" & countryname == "Slovakia"
replace pop_temp_left = 1 if date == "201603" & countryname == "Slovakia"
* Zuma 2009-2018
replace pop_temp_left = 1 if date == "201405" & countryname == "South Africa"

* Menem 1989-1999
replace pop_temp_right = 1 if date == "199505" & countryname == "Argentina"
replace pop_temp_right = 1 if date == "199910" & countryname == "Argentina"
* Borisov 2009-2013; 2014-2017; 2017-2018
replace pop_temp_right = 1 if date == "201305" & countryname == "Bulgaria"
replace pop_temp_right = 1 if date == "201703" & countryname == "Bulgaria"
* Orban 2010-2018
replace pop_temp_right = 1 if date == "201404" & countryname == "Hungary"
replace pop_temp_right = 1 if date == "201804" & countryname == "Hungary"
* Netanyahu 1996-1999; 2009-2018
replace pop_temp_right = 1 if date == "199905" & countryname == "Israel"
replace pop_temp_right = 1 if date == "201301" & countryname == "Israel"
replace pop_temp_right = 1 if date == "201503" & countryname == "Israel"
* Berlusconi 2001-2006; 2008-2011         
replace pop_temp_right = 1 if date == "200604" & countryname == "Italy"
* Muldoon 1975-1984
replace pop_temp_right = 1 if date == "197811" & countryname == "New Zealand"
replace pop_temp_right = 1 if date == "198111" & countryname == "New Zealand"
replace pop_temp_right = 1 if date == "198407" & countryname == "New Zealand"
* Kaczynskis 2005-2007; 2015-2018
replace pop_temp_right = 1 if date == "200710" & countryname == "Poland"
* Meciar 1990-1991; 1992-1994; 1994-1998
replace pop_temp_right = 1 if date == "199409" & countryname == "Slovakia"
replace pop_temp_right = 1 if date == "199809" & countryname == "Slovakia"
* Erdogan 2003-2018
replace pop_temp_right = 1 if date == "200707" & countryname == "Turkey"
replace pop_temp_right = 1 if date == "201106" & countryname == "Turkey"
replace pop_temp_right = 1 if date == "201506" & countryname == "Turkey"
replace pop_temp_right = 1 if date == "201511" & countryname == "Turkey"
replace pop_temp_right = 1 if date == "201806" & countryname == "Turkey"

gen temp = "1 Non-populist"
replace temp = "2 Left populist" if pop_temp_left == 1
replace temp = "3 Right populist" if pop_temp_right == 1
encode temp, gen(pop)
label define pop 1 "Non-populist" 2 "Left populist" ///
                  3 "Right populist", replace

drop temp pop_temp pop_temp_left pop_temp_right



**** create control variable that captures party pairs where one party provides a non-populist leader
gen leader = 0
replace leader = 1 if party_type2 == "party with non-populist incumbent leader"


**** create ID variables (for fixed effects / clustering)
egen country_id = group(countryname)
egen election_id = group(countryname date)


/**** group parties into left and right, using Abou-Chadi and Krause's 2018 definition:
*    --> a party is assigned to the left bloc if its mean right-left score in the sample
*        is smaller than the country's mean right-left score, and to the right bloc if
*        the opposite applies
bysort party1 (date): egen p_mean_rile1 = mean(rile1)
bysort party2 (date): egen p_mean_rile2 = mean(rile2)

gen left1 = 0
replace left1 = 1 if p_mean_rile1 <= rile_country_mean

gen left2 = 0
replace left2 = 1 if p_mean_rile2 <= rile_country_mean


**** create variable that captures possible left-right constellations betweeen party pairs
gen temp = "x Left-Left"
replace temp = "x Left-Right" if (left1 == 1 & left2 == 0) | (left1 == 0 & left2 == 1)
replace temp = "x Right-Right" if left1 == 0 & left2 == 0
encode temp, gen(lr_constellation)
drop left1 left2 temp p_mean_rile1 p_mean_rile2
*/

**** create combined treatment indicator interacted with ideological constellation betweeen party pairs
*egen combined_treat_var = group(pop lr_constellation), label
*recode combined_treat_var (1 2 3  = 1)

**** drop comparisons with populists' parties (since we're interested in competition between mainstream parties)
drop if party_type2 == "party with left-wing populist incumbent leader" | ///
        party_type2 == "party with right-wing populist incumbent leader"
		

************************************************************************
* create indicators for treated elections along political ideology
************************************************************************
gen pop_temp = 0
replace pop_temp= 1 if pop == 2
replace pop_temp= 1 if pop == 3

*left-wing populist
gen pop_left = 0
replace pop_left= 1 if pop == 2

*right-wing populist
gen pop_right = 0
replace pop_right = 1 if pop==3


***************************************************************************
* Strength of Populist Parties in Parliament                              *
* (based on Votes for Populists Database of the Global Populisms Project) *
***************************************************************************
gen pop_vote_share = 0

*Argentina
replace pop_vote_share = 44.684 if date == "198905" & country_id == 1

*Austria
replace pop_vote_share = 26.91 if date == "199910" & country_id == 4 
replace pop_vote_share = 10.01 if date == "200211" & country_id == 4  
replace pop_vote_share = 15.15 if date == "200610" & country_id == 4
replace pop_vote_share = 28.24 if date == "200809" & country_id == 4
replace pop_vote_share = 20.506 if date == "201309" & country_id == 4
replace pop_vote_share = 25.966 if date == "201710" & country_id == 4


*Belgium
replace pop_vote_share = 11.99 if date == "200706" & country_id == 5
replace pop_vote_share = 7.763 if date == "201006" & country_id == 5
replace pop_vote_share = 3.673 if date == "201405" & country_id == 5

*Bulgaria
replace pop_vote_share = 49.084 if date == "200907" & country_id == 8
replace pop_vote_share =7.298 if date == "201305" & country_id == 8
replace pop_vote_share = 42.876 if date == "201410" & country_id == 8


*Croatia
replace pop_vote_share = 5.19 if date == "200001" & country_id == 11
replace pop_vote_share = 40.313  if date == "200311" & country_id == 11
replace pop_vote_share = 36.552  if date == "200711" & country_id == 11
replace pop_vote_share = 23.919  if date == "201112" & country_id == 11
replace pop_vote_share = 32.911  if date == "201609" & country_id == 11

*Czech Republic
replace pop_vote_share = 12.81  if date == "200606" & country_id == 13
replace pop_vote_share = 22.15  if date == "201005" & country_id == 13
replace pop_vote_share = 33.567  if date == "201310" & country_id == 13
replace pop_vote_share = 48.052 if date == "201710" & country_id == 13


*Denmark
replace pop_vote_share = 7.41 if date == "199803" & country_id == 14
replace pop_vote_share = 13.253 if date == "200502" & country_id == 14
replace pop_vote_share = 13.86 if date == "200711" & country_id == 14
replace pop_vote_share = 12.303 if date == "201109" & country_id == 14
replace pop_vote_share = 21.078 if date == "201506" & country_id == 14

*Estonia
replace pop_vote_share = 17.87 if date == "200703" & country_id == 15
replace pop_vote_share = 20.521 if date == "201103" & country_id == 15
replace pop_vote_share = 13.7 if date == "201503" & country_id == 15


*Finland
replace pop_vote_share = 4.05 if date == "200703" & country_id == 16
replace pop_vote_share = 19.053 if date == "201104" & country_id == 16
replace pop_vote_share = 17.654 if date == "201504" & country_id == 16

*France
replace pop_vote_share = 13.596 if date == "201206" & country_id == 17
replace pop_vote_share = 13.2 if date == "201706" & country_id == 17

*Georgia
replace pop_vote_share = 5.007 if date == "201610" & country_id == 18

*Germany
replace pop_vote_share = 8.709 if date == "200509" & country_id == 19
replace pop_vote_share = 11.888 if date == "200909" & country_id == 19
replace pop_vote_share = 8.6 if date == "201309" & country_id == 19
replace pop_vote_share = 21.875 if date == "201709" & country_id == 19

*Greece
replace pop_vote_share = 5.896 if date == "200403" &  country_id == 20
replace pop_vote_share = 12.143 if date == "200910" & country_id == 20
replace pop_vote_share = 28.204 if date == "201205" & country_id == 20
replace pop_vote_share = 47.817 if date == "201501" & country_id == 20

*Hungary
replace pop_vote_share = 42.49 if date == "200604" & country_id == 21
replace pop_vote_share = 80.06 if date == "201004" & country_id == 21
replace pop_vote_share = 20.853 if date == "201404" & country_id == 21
replace pop_vote_share = 19.064 if date == "201804" & country_id == 21

*Israel
replace pop_vote_share = 43.13 if date == "200301" & country_id == 24
replace pop_vote_share = 27.507 if date == "200603" & country_id == 24
replace pop_vote_share = 41.794 if date == "200902" & country_id == 24
replace pop_vote_share = 10.842 if date == "201503" & country_id == 24

*Italy
replace pop_vote_share = 45.29 if date == "200804" & country_id == 25
replace pop_vote_share = 50.982 if date == "201302" & country_id == 25
replace pop_vote_share = 63.178 if date == "201803" & country_id == 25

*Japan
replace pop_vote_share = 6.075 if date == "201710" & country_id == 26


*Latvia
replace pop_vote_share = 6.941 if date == "200610" & country_id == 27
replace pop_vote_share = 7.835 if date == "201010" & country_id == 27
replace pop_vote_share = 14.006 if date == "201109" & country_id == 27
replace pop_vote_share = 16.719 if date == "201410" & country_id == 27
replace pop_vote_share = 11.08 if date == "201810" & country_id == 27


*Lithuania
replace pop_vote_share = 51.815 if date == "200410" & country_id == 28
replace pop_vote_share = 32.392 if date == "200810" & country_id == 28
replace pop_vote_share = 52.412 if date == "201210" & country_id == 28
replace pop_vote_share = 28.184 if date == "201610" & country_id == 28

*Mexico
replace pop_vote_share = 34.522 if date == "200306" & country_id == 30
replace pop_vote_share = 12.891 if date == "200907" & country_id == 30
replace pop_vote_share = 19.357 if date == "201207" & country_id == 30
replace pop_vote_share = 8.813 if date == "201506" & country_id == 30
replace pop_vote_share = 38.797 if date == "201807" & country_id == 30	

*Moldova		
replace pop_vote_share = 20.513 if date == "201411" & country_id == 31	

*Netherlands
replace pop_vote_share = 22.465 if date == "200611" & country_id == 33
replace pop_vote_share = 25.28 if date == "201006" & country_id == 33
replace pop_vote_share = 19.737 if date == "201209" & country_id == 33
replace pop_vote_share = 22.143 if date == "201703" & country_id == 33

*North Macedonia
replace pop_vote_share = 20.5 if date == "200209" & country_id == 35
replace pop_vote_share = 6.091 if date == "200607" & country_id == 35
replace pop_vote_share = 39.949 if date == "200806" & country_id == 35
replace pop_vote_share = 32.714 if date == "201106" & country_id == 35
replace pop_vote_share = 44.467 if date == "201404" & country_id == 35
replace pop_vote_share = 39.392 if date == "201612" & country_id == 35

*Poland
replace pop_vote_share = 18.073 if date == "200109" & country_id == 37
replace pop_vote_share = 29.89 if date == "201110" & country_id == 37
replace pop_vote_share = 37.575 if date == "201510" & country_id == 37


*Romania
replace pop_vote_share = 4.465 if date == "199611" & country_id == 39
replace pop_vote_share = 19.485 if date == "200011" & country_id == 39
replace pop_vote_share = 44.44 if date == "200411" & country_id == 39
replace pop_vote_share = 32.364 if date == "200811" & country_id == 39


*Serbia
replace pop_vote_share = 8.344 if date == "201604" & country_id == 41

*Slovakia
replace pop_vote_share = 40.879 if date == "200606" & country_id == 42
replace pop_vote_share = 5.08 if date == "201006" & country_id == 42
replace pop_vote_share = 44.417 if date == "201203" & country_id == 42
replace pop_vote_share = 8.643 if date == "201603" & country_id == 42

*Slovenia
replace pop_vote_share = 29.079 if date == "200410" & country_id == 43
replace pop_vote_share = 29.257 if date == "200809" & country_id == 43
replace pop_vote_share = 26.193 if date == "201112" & country_id == 43
replace pop_vote_share = 20.708 if date == "201407" & country_id == 43
replace pop_vote_share = 24.918 if date == "201806" & country_id == 43

*Sweden
replace pop_vote_share = 5.7 if date == "201009" & country_id == 46
replace pop_vote_share = 12.857 if date == "201409" & country_id == 46
replace pop_vote_share = 17.534 if date == "201809" & country_id == 46

*Turkey
replace pop_vote_share = 34.17 if date == "200211" & country_id == 47
replace pop_vote_share = 12.752 if date == "201506" & country_id == 47
replace pop_vote_share = 11.702 if date == "201806" & country_id == 47

*UK
replace pop_vote_share = 12.629 if date == "201505" & country_id == 49
replace pop_vote_share = 1.845 if date == "201706" & country_id == 49


*****************************************
* Replacement with pre-treatment values *
*****************************************
*Argentina
replace gdp_pc = 8473.0266 if country_id==1 & year> 1989 & year <= 1999
replace unemp = 7.3  if country_id==1 & year> 1989 & year <= 1999
replace inflation = 3046.0912 if country_id==1 & year> 1989 & year <= 1999
replace institutions = 1.651445  if country_id==1 & year> 1989 & year <= 1999
replace pop_vote_share = 44.684 if country_id==1 & year> 1989 & year <= 1999

replace gdp_pc = 12857.093 if country_id==1 & year> 2007
replace unemp = 8.47 if country_id==1 & year> 2007
replace inflation = 14.939925 if country_id==1 & year> 2007
replace institutions = 1.358388 if country_id==1 & year> 2007

*Bolivia
replace gdp_pc = 2216.5447 if country_id==6 & pop_temp==1
replace unemp = 5.08  if country_id==6 & pop_temp==1
replace inflation = 13.66368 if country_id==6 & pop_temp==1
replace institutions = .9948081  if country_id==6 & pop_temp==1
replace pop_vote_share = 53.74  if country_id==6 & pop_temp==1

*Bulgaria
replace gdp_pc = 6294.3853 if country_id==8 & year==2013
replace unemp = 6.82  if country_id==8 & year==2013
replace inflation = 3.8571196 if country_id==8 & year==2013
replace institutions = 1.438843  if country_id==8 & year==2013
replace pop_vote_share = 49.084  if country_id==8 & year==2013

replace gdp_pc = 6802.8581 if country_id==8 & year>2014
replace unemp = 11.42  if country_id==8 & year>2014
replace inflation = 1.3407402 if country_id==8 & year>2014
replace institutions = 1.351155  if country_id==8 & year>2014
replace pop_vote_share = 42.876 if country_id==8 & year>2014

*Greece
replace pop_vote_share = 47.817 if date == "201509" & country_id == 20

*Hungary
replace gdp_pc = 11307.716 if country_id==21 & pop_temp==1
replace unemp = 11.17 if country_id==21 & pop_temp==1
replace inflation = 2.5325705 if country_id==21 & pop_temp==1
replace institutions = 1.660717 if country_id==21 & pop_temp==1
replace pop_vote_share = 80.06 if country_id==21 & pop_temp==1

*Israel
replace gdp_pc = 31852.267 if country_id==24 &  pop_temp==1
replace unemp = 9.53 if country_id==24 &  pop_temp==1
replace inflation = 4.4192118 if country_id==24 &  pop_temp==1
replace institutions= 1.770723 if country_id==24 &  pop_temp==1
replace pop_vote_share = 41.794 if country_id==24 &  pop_temp==1

*Poland 
replace gdp_pc = 8554.6939 if country_id==37 &  pop_temp==1
replace unemp = 17.75 if country_id==37 &  pop_temp==1
replace inflation = 2.5591955 if country_id==37 &  pop_temp==1
replace institutions = 2.177494 if country_id==37 &  pop_temp==1
replace pop_vote_share = 54.04 if country_id==37 &  pop_temp==1


*Slovakia
replace gdp_pc = 12395.752 if country_id==42 & year> 2006 & year<= 2010
replace unemp = 13.39 if country_id==42 & year> 2006 & year<= 2010
replace inflation = 2.899074 if country_id==42 & year> 2006 & year<= 2010
replace institutions = 1.897356 if country_id==42 & year> 2006 & year<= 2010
replace pop_vote_share = 40.879 if country_id==42 & year> 2006 & year<= 2010

replace gdp_pc = 15126.035 if country_id==42 & year> 2012
replace unemp = 13.97 if country_id==42 & year> 2012
replace inflation = 1.2603677 if country_id==42 & year> 2012
replace institutions = 1.931833 if country_id==42 & year> 2012
replace pop_vote_share = 44.417 if country_id==42 & year> 2012

*South Africa
replace gdp_pc = 5910.7882 if country_id==44 &  pop_temp==1
replace unemp = 20.51 if country_id==44 &  pop_temp==1
replace inflation = 8.6630418 if country_id==44 &  pop_temp==1
replace institutions = 1.687343 if country_id==44 &  pop_temp==1
replace pop_vote_share = 65.895 if country_id==44 &  pop_temp==1


*Turkey
replace gdp_pc = 6566.8283 if country_id==47 &  pop_temp==1
replace unemp = 10.55 if country_id==47 &  pop_temp==1
replace inflation = 23.289281  if country_id==47 &  pop_temp==1
replace institutions = 1.758138 if country_id==47 &  pop_temp==1
replace pop_vote_share = 34.17 if country_id==47 &  pop_temp==1

drop if missing(unemp)


***************************************************************
* emerging economies indicator (advanced = 0)                 *
* (based on the International Monetary Fund's classification) *
***************************************************************
gen emerging = 0
replace emerging = 1 if country_id==1
replace emerging = 1 if country_id==2
replace emerging = 1 if country_id==6
replace emerging = 1 if country_id==7
replace emerging = 1 if country_id==8
replace emerging = 1 if country_id==10
replace emerging = 1 if country_id==18
replace emerging = 1 if country_id==21
replace emerging = 1 if country_id==30
replace emerging = 1 if country_id==31
replace emerging = 1 if country_id==32
replace emerging = 1 if country_id==35
replace emerging = 1 if country_id==37
replace emerging = 1 if country_id==39
replace emerging = 1 if country_id==40
replace emerging = 1 if country_id==41
replace emerging = 1 if country_id==44
replace emerging = 1 if country_id==47
replace emerging = 1 if country_id==48
replace emerging = 1 if country_id==51


***************************************************************************************************************
* Alternative definition of populists                                                                         *
* (reclassify Boyko Borisov, Robert Fico, Cristina Fernández de Kirchner, and Aléxis Tsípras as non-populist) *
***************************************************************************************************************
gen party_type2_v2 = party_type2

*Fernández
*2009
replace party_type2_v2 ="party with non-populist incumbent leader" if country_id==1 & year==2009 & partyname2 == "Front for Victory"
*2011
replace party_type2_v2 ="party with non-populist incumbent leader" if country_id==1 & year==2011 & partyname2 == "Front for Victory"
*2013
replace party_type2_v2 ="party with non-populist incumbent leader" if country_id==1 & year==2013 & partyname2 == "Front for Victory"

*Boyko Borisov 
*2013
replace party_type2_v2 ="party with non-populist incumbent leader" if country_id==8 & year==2013 & partyname2 == "Citizens for European Development of Bulgaria"
*2017
replace party_type2_v2 ="party with non-populist incumbent leader" if country_id==8 & year==2017  & partyname2 == "Citizens for European Development of Bulgaria"

*Aléxis Tsípras 
replace party_type2_v2 ="party with non-populist incumbent leader" if country_id==20 & date=="201509" & partyname2 == "Coalition of the Radical Left"

*Robert Fico
*2010
replace party_type2_v2 ="party with non-populist incumbent leader" if country_id==42 & year==2010 & partyname2 == "Direction-Social Democracy"
*2016
replace party_type2_v2 ="party with non-populist incumbent leader" if country_id==42 & year==2016 & partyname2 == "Direction-Social Democracy"


** create indicators for treated elections 
gen pop_temp_v2 = 0
gen pop_temp_left_v2 = 0
gen pop_temp_right_v2 = 0

* Kirchner 2003-2007
replace pop_temp_left_v2 = 1 if date == "200710" & countryname == "Argentina"
* Morales 2006-2018
replace pop_temp_left_v2 = 1 if date == "200912" & countryname == "Bolivia"
replace pop_temp_left_v2 = 1 if date == "201410" & countryname == "Bolivia"
* Correa 2007-2017
replace pop_temp_left_v2 = 1 if date == "200904" & countryname == "Ecuador"
replace pop_temp_left_v2 = 1 if date == "201302" & countryname == "Ecuador"
replace pop_temp_left_v2 = 1 if date == "201702" & countryname == "Ecuador"
* Zuma 2009-2018
replace pop_temp_left_v2 = 1 if date == "201405" & countryname == "South Africa"

* Menem 1989-1999
replace pop_temp_right_v2 = 1 if date == "199505" & countryname == "Argentina"
replace pop_temp_right_v2 = 1 if date == "199910" & countryname == "Argentina"
* Orban 2010-2018
replace pop_temp_right_v2 = 1 if date == "201404" & countryname == "Hungary"
replace pop_temp_right_v2 = 1 if date == "201804" & countryname == "Hungary"
* Netanyahu 1996-1999; 2009-2018
replace pop_temp_right_v2 = 1 if date == "199905" & countryname == "Israel"
replace pop_temp_right_v2 = 1 if date == "201301" & countryname == "Israel"
replace pop_temp_right_v2 = 1 if date == "201503" & countryname == "Israel"
* Berlusconi 2001-2006; 2008-2011         
replace pop_temp_right_v2 = 1 if date == "200604" & countryname == "Italy"
* Muldoon 1975-1984
replace pop_temp_right_v2 = 1 if date == "197811" & countryname == "New Zealand"
replace pop_temp_right_v2 = 1 if date == "198111" & countryname == "New Zealand"
replace pop_temp_right_v2 = 1 if date == "198407" & countryname == "New Zealand"
* Kaczynskis 2005-2007; 2015-2018
replace pop_temp_right_v2 = 1 if date == "200710" & countryname == "Poland"
* Meciar 1990-1991; 1992-1994; 1994-1998
replace pop_temp_right_v2 = 1 if date == "199409" & countryname == "Slovakia"
replace pop_temp_right_v2 = 1 if date == "199809" & countryname == "Slovakia"
* Erdogan 2003-2018
replace pop_temp_right_v2 = 1 if date == "200707" & countryname == "Turkey"
replace pop_temp_right_v2 = 1 if date == "201106" & countryname == "Turkey"
replace pop_temp_right_v2 = 1 if date == "201506" & countryname == "Turkey"
replace pop_temp_right_v2 = 1 if date == "201511" & countryname == "Turkey"
replace pop_temp_right_v2 = 1 if date == "201806" & countryname == "Turkey"


gen temp_v2 = "1 Non-populist"
replace temp_v2 = "2 Left populist" if pop_temp_left_v2 == 1
replace temp_v2 = "3 Right populist" if pop_temp_right_v2 == 1
encode temp_v2, gen(pop_v2)
label define pop_v2 1 "Non-populist" 2 "Left populist" ///
                  3 "Right populist", replace

drop temp_v2 pop_temp_v2 pop_temp_left_v2 pop_temp_right_v2


gen leader_v2 = 0
replace leader_v2 = 1 if party_type2 == "party with non-populist incumbent leader"

gen pop_temp_v2 = 0
replace pop_temp_v2 = 1 if pop_v2 == 2
replace pop_temp_v2= 1 if pop_v2 == 3

gen pop_vote_share_v2 = 0

*Argentina
replace pop_vote_share_v2 = 44.684 if date == "198905" & country_id == 1
replace pop_vote_share_v2 = 30.28 if date == "200906"  & country_id == 1
replace pop_vote_share_v2 = 49.1 if date == "201110"  & country_id == 1
replace pop_vote_share_v2 = 33.15 if date == "201310"  & country_id == 1

*Austria
replace pop_vote_share_v2 = 26.91 if date == "199910" & country_id == 4 
replace pop_vote_share_v2 = 10.01 if date == "200211" & country_id == 4  
replace pop_vote_share_v2 = 15.15 if date == "200610" & country_id == 4
replace pop_vote_share_v2 = 28.24 if date == "200809" & country_id == 4
replace pop_vote_share_v2 = 20.506 if date == "201309" & country_id == 4
replace pop_vote_share_v2 = 25.966 if date == "201710" & country_id == 4


*Belgium
replace pop_vote_share_v2 = 11.99 if date == "200706" & country_id == 5
replace pop_vote_share_v2 = 7.763 if date == "201006" & country_id == 5
replace pop_vote_share_v2 = 3.673 if date == "201405" & country_id == 5

*Bulgaria
replace pop_vote_share_v2 = 49.084 if date == "200907" & country_id == 8
replace pop_vote_share_v2 =37.837 if date == "201305" & country_id == 8
replace pop_vote_share_v2 = 42.876 if date == "201410" & country_id == 8


*Croatia
replace pop_vote_share_v2 = 5.19 if date == "200001" & country_id == 11
replace pop_vote_share_v2 = 40.313  if date == "200311" & country_id == 11
replace pop_vote_share_v2 = 36.552  if date == "200711" & country_id == 11
replace pop_vote_share_v2 = 23.919  if date == "201112" & country_id == 11
replace pop_vote_share_v2 = 32.911  if date == "201609" & country_id == 11

*Czech Republic
replace pop_vote_share_v2 = 12.81  if date == "200606" & country_id == 13
replace pop_vote_share_v2 = 22.15  if date == "201005" & country_id == 13
replace pop_vote_share_v2 = 33.567  if date == "201310" & country_id == 13
replace pop_vote_share_v2 = 48.052 if date == "201710" & country_id == 13


*Denmark
replace pop_vote_share_v2 = 7.41 if date == "199803" & country_id == 14
replace pop_vote_share_v2 = 13.253 if date == "200502" & country_id == 14
replace pop_vote_share_v2 = 13.86 if date == "200711" & country_id == 14
replace pop_vote_share_v2 = 12.303 if date == "201109" & country_id == 14
replace pop_vote_share_v2 = 21.078 if date == "201506" & country_id == 14

*Estonia
replace pop_vote_share_v2 = 17.87 if date == "200703" & country_id == 15
replace pop_vote_share_v2 = 20.521 if date == "201103" & country_id == 15
replace pop_vote_share_v2 = 13.7 if date == "201503" & country_id == 15


*Finland
replace pop_vote_share_v2 = 4.05 if date == "200703" & country_id == 16
replace pop_vote_share_v2 = 19.053 if date == "201104" & country_id == 16
replace pop_vote_share_v2 = 17.654 if date == "201504" & country_id == 16

*France
replace pop_vote_share_v2 = 13.596 if date == "201206" & country_id == 17
replace pop_vote_share_v2 = 13.2 if date == "201706" & country_id == 17

*Georgia
replace pop_vote_share_v2 = 5.007 if date == "201610" & country_id == 18

*Germany
replace pop_vote_share_v2 = 8.709 if date == "200509" & country_id == 19
replace pop_vote_share_v2 = 11.888 if date == "200909" & country_id == 19
replace pop_vote_share_v2 = 8.6 if date == "201309" & country_id == 19
replace pop_vote_share_v2 = 21.875 if date == "201709" & country_id == 19

*Greece
replace pop_vote_share_v2 = 5.896 if date == "200403" &  country_id == 20
replace pop_vote_share_v2 = 12.143 if date == "200910" & country_id == 20
replace pop_vote_share_v2 = 28.204 if date == "201205" & country_id == 20
replace pop_vote_share_v2 = 47.817 if date == "201501" & country_id == 20
replace pop_vote_share_v2 = 40.878 if date == "201509" & country_id == 20

*Hungary
replace pop_vote_share_v2 = 42.49 if date == "200604" & country_id == 21
replace pop_vote_share_v2 = 80.06 if date == "201004" & country_id == 21
replace pop_vote_share_v2 = 20.853 if date == "201404" & country_id == 21
replace pop_vote_share_v2 = 19.064 if date == "201804" & country_id == 21

*Israel
replace pop_vote_share_v2 = 43.13 if date == "200301" & country_id == 24
replace pop_vote_share_v2 = 27.507 if date == "200603" & country_id == 24
replace pop_vote_share_v2 = 41.794 if date == "200902" & country_id == 24
replace pop_vote_share_v2 = 10.842 if date == "201503" & country_id == 24

*Italy
replace pop_vote_share_v2 = 45.29 if date == "200804" & country_id == 25
replace pop_vote_share_v2 = 50.982 if date == "201302" & country_id == 25
replace pop_vote_share_v2 = 63.178 if date == "201803" & country_id == 25

*Japan
replace pop_vote_share_v2 = 6.075 if date == "201710" & country_id == 26


*Latvia
replace pop_vote_share_v2 = 6.941 if date == "200610" & country_id == 27
replace pop_vote_share_v2 = 7.835 if date == "201010" & country_id == 27
replace pop_vote_share_v2 = 14.006 if date == "201109" & country_id == 27
replace pop_vote_share_v2 = 16.719 if date == "201410" & country_id == 27
replace pop_vote_share_v2 = 11.08 if date == "201810" & country_id == 27


*Lithuania
replace pop_vote_share_v2 = 51.815 if date == "200410" & country_id == 28
replace pop_vote_share_v2 = 32.392 if date == "200810" & country_id == 28
replace pop_vote_share_v2 = 52.412 if date == "201210" & country_id == 28
replace pop_vote_share_v2 = 28.184 if date == "201610" & country_id == 28

*Mexico
replace pop_vote_share_v2 = 34.522 if date == "200306" & country_id == 30
replace pop_vote_share_v2 = 12.891 if date == "200907" & country_id == 30
replace pop_vote_share_v2 = 19.357 if date == "201207" & country_id == 30
replace pop_vote_share_v2 = 8.813 if date == "201506" & country_id == 30
replace pop_vote_share_v2 = 38.797 if date == "201807" & country_id == 30	

*Moldova		
replace pop_vote_share_v2 = 20.513 if date == "201411" & country_id == 31	

*Netherlands
replace pop_vote_share_v2 = 22.465 if date == "200611" & country_id == 33
replace pop_vote_share_v2 = 25.28 if date == "201006" & country_id == 33
replace pop_vote_share_v2 = 19.737 if date == "201209" & country_id == 33
replace pop_vote_share_v2 = 22.143 if date == "201703" & country_id == 33

*North Macedonia
replace pop_vote_share_v2 = 20.5 if date == "200209" & country_id == 35
replace pop_vote_share_v2 = 6.091 if date == "200607" & country_id == 35
replace pop_vote_share_v2 = 39.949 if date == "200806" & country_id == 35
replace pop_vote_share_v2 = 32.714 if date == "201106" & country_id == 35
replace pop_vote_share_v2 = 44.467 if date == "201404" & country_id == 35
replace pop_vote_share_v2 = 39.392 if date == "201612" & country_id == 35

*Poland
replace pop_vote_share_v2 = 18.073 if date == "200109" & country_id == 37
replace pop_vote_share_v2 = 29.89 if date == "201110" & country_id == 37
replace pop_vote_share_v2 = 37.575 if date == "201510" & country_id == 37


*Romania
replace pop_vote_share_v2 = 4.465 if date == "199611" & country_id == 39
replace pop_vote_share_v2 = 19.485 if date == "200011" & country_id == 39
replace pop_vote_share_v2 = 44.44 if date == "200411" & country_id == 39
replace pop_vote_share_v2 = 32.364 if date == "200811" & country_id == 39


*Serbia
replace pop_vote_share_v2 = 8.344 if date == "201604" & country_id == 41

*Slovakia
replace pop_vote_share_v2 = 40.879 if date == "200606" & country_id == 42
replace pop_vote_share_v2 = 39.875 if date == "201006" & country_id == 42
replace pop_vote_share_v2 = 44.417 if date == "201203" & country_id == 42
replace pop_vote_share_v2 = 36.923 if date == "201603" & country_id == 42

*Slovenia
replace pop_vote_share_v2 = 29.079 if date == "200410" & country_id == 43
replace pop_vote_share_v2 = 29.257 if date == "200809" & country_id == 43
replace pop_vote_share_v2 = 26.193 if date == "201112" & country_id == 43
replace pop_vote_share_v2 = 20.708 if date == "201407" & country_id == 43
replace pop_vote_share_v2 = 24.918 if date == "201806" & country_id == 43

*Sweden
replace pop_vote_share_v2 = 5.7 if date == "201009" & country_id == 46
replace pop_vote_share_v2 = 12.857 if date == "201409" & country_id == 46
replace pop_vote_share_v2 = 17.534 if date == "201809" & country_id == 46

*Turkey
replace pop_vote_share_v2 = 34.17 if date == "200211" & country_id == 47
replace pop_vote_share_v2 = 12.752 if date == "201506" & country_id == 47
replace pop_vote_share_v2 = 11.702 if date == "201806" & country_id == 47

*UK
replace pop_vote_share_v2 = 12.629 if date == "201505" & country_id == 49
replace pop_vote_share_v2 = 1.845 if date == "201706" & country_id == 49



** replacement with pre-treatment values
gen gdp_pc_v2 = gdp_pc
gen unemp_v2 = unemp
gen inflation_v2 = inflation
gen institutions_v2 = institutions

*Argentina
replace gdp_pc_v2 = 8473.0266 if country_id==1 & year> 1989 & year <= 1999
replace unemp_v2 = 7.3  if country_id==1 & year> 1989 & year <= 1999
replace inflation_v2 = 3046.0912 if country_id==1 & year> 1989 & year <= 1999
replace institutions_v2 = 1.651445  if country_id==1 & year> 1989 & year <= 1999
replace pop_vote_share_v2 = 44.684 if country_id==1 & year> 1989 & year <= 1999

*Bolivia
replace gdp_pc_v2 = 2216.5447 if country_id==6 & pop_temp==1
replace unemp_v2 = 5.08  if country_id==6 & pop_temp==1
replace inflation_v2 = 13.66368 if country_id==6 & pop_temp==1
replace institutions_v2 = .9948081  if country_id==6 & pop_temp==1
replace pop_vote_share_v2 = 53.74  if country_id==6 & pop_temp==1


*Hungary
replace gdp_pc_v2 = 11307.716 if country_id==21 & pop_temp==1
replace unemp_v2 = 11.17 if country_id==21 & pop_temp==1
replace inflation_v2 = 2.5325705 if country_id==21 & pop_temp==1
replace institutions_v2 = 1.660717 if country_id==21 & pop_temp==1
replace pop_vote_share_v2 = 80.06 if country_id==21 & pop_temp==1

*Israel
replace gdp_pc_v2 = 31852.267 if country_id==24 &  pop_temp==1
replace unemp_v2 = 9.53 if country_id==24 &  pop_temp==1
replace inflation_v2 = 4.4192118 if country_id==24 &  pop_temp==1
replace institutions_v2= 1.770723 if country_id==24 &  pop_temp==1
replace pop_vote_share_v2 = 41.794 if country_id==24 &  pop_temp==1

*Poland 
replace gdp_pc_v2 = 8554.6939 if country_id==37 &  pop_temp==1
replace unemp_v2 = 17.75 if country_id==37 &  pop_temp==1
replace inflation_v2 = 2.5591955 if country_id==37 &  pop_temp==1
replace institutions_v2 = 2.177494 if country_id==37 &  pop_temp==1
replace pop_vote_share_v2 = 54.04 if country_id==37 &  pop_temp==1



*South Africa
replace gdp_pc_v2 = 5910.7882 if country_id==44 &  pop_temp==1
replace unemp_v2 = 20.51 if country_id==44 &  pop_temp==1
replace inflation_v2 = 8.6630418 if country_id==44 &  pop_temp==1
replace institutions_v2 = 1.687343 if country_id==44 &  pop_temp==1
replace pop_vote_share_v2 = 65.895 if country_id==44 &  pop_temp==1


*Turkey
replace gdp_pc_v2 = 6566.8283 if country_id==47 &  pop_temp==1
replace unemp_v2 = 10.55 if country_id==47 &  pop_temp==1
replace inflation_v2 = 23.289281  if country_id==47 &  pop_temp==1
replace institutions_v2 = 1.758138 if country_id==47 &  pop_temp==1
replace pop_vote_share_v2 = 34.17 if country_id==47 &  pop_temp==1



* parliamentary vs. presidential
merge m:1 countryname year using "other_raw_data/database_political_institutions.dta"
drop if _merge == 2
drop _merge
drop ifs yrsoffc finittrm yrcurnt termlimit reelect multpl military defmin percent1 ///
percentl prtyin execme execrlc execnat execrurl execreg execrel execage allhouse nonchief ///
 totalseats gov1me gov1seat gov1vote gov1rlc gov1nat gov1rurl gov1reg gov1rel gov1age gov2me ///
 gov2seat gov2vote gov2rlc gov2nat gov2rurl gov2reg gov2rel gov2age gov3me gov3seat gov3vote ///
 gov3rlc gov3nat gov3rurl gov3reg gov3rel gov3age govoth govothst govothvt opp1me opp1seat ///
 opp1vote opp1rlc opp1nat opp1rurl opp1reg opp1rel opp1age opp2me opp2seat opp2vote opp3me ///
 opp3seat opp3vote oppoth oppothst oppothvt ulprty numul ulvote oppmajh oppmajs dateleg dateexec ///
 legelec exelec liec eiec mdmh mdms ssh pluralty pr housesys sensys thresh dhondt cl select gq ///
 gqi fraud auton muni state author stconst gwno numgov numvote numopp oppvote maj partyage herfgov ///
 herfopp herftot frac oppfrac govfrac tensys_strict tensys checks_lax checks stabs_strict stabs ///
 stabns_strict stabns tenlong_strict tenlong tenshort_strict tenshort polariz
gen presidential = 0
replace presidential = 1 if system =="Presidential"
replace presidential = 1 if system =="Assembly-Elected President"


************* clean up
drop index rile_country_mean parfam1 parfam2 pervote1 pervote2 rile1 rile2 CountryCode ///
 media election judicial system pop_left pop_right party_type2_v2
 
label variable countryname "Name of country"
label variable date "Date of election (YYYYMM)"
label variable year "Year of election (YYYY)
label variable party1 "Manifesto Project ID of party 1"
label variable party_type1 "Type of party 1"
label variable partyname1 "Name of party 1"
label variable party2 "Manifesto Project ID of party 2"
label variable party_type2 "Type of party 2"
label variable partyname2 "Name of party 2"
label variable cos_multicult "Difference in positions on multiculturalism (cosine distance)"
label variable cos_combo "Difference in positions on equality/welfare (cosine distance)"
label variable diff_combo "Difference in positions on equality/welfare (traditional measure)"
label variable diff_multicult "Difference in positions on multiculturalism (traditional measure)"
label variable institutions "Quality of institutions (index)"
label variable gdp_pc "GDP per capita (USD)"
label variable inflation "Inflation rate (%)"
label variable unemp "Unemployment rate (%)"
label variable pop "Treatment indicator"
label variable leader "1 if party-pair with a state leader"
label variable country_id "Country ID"
label variable election_id "Election ID"
label variable pop_temp "1 if any populist state leader"
label variable pop_vote_share "Aggregate populist vote share (%)"
label variable emerging "1 if emerging country, 0 if advanced economy"
label variable pop_v2 "Treatment indicator (alternative populism definition)"
label variable leader_v2 "1 if party-pair with a state leader (alternative populism definition)"
label variable pop_temp_v2 "1 if any populist state leader (alternative populism definition)"
label variable pop_vote_share_v2 "Aggregate populist vote share (alternative populism definition)"
label variable gdp_pc_v2 "GDP per capita (alternative populism definition)"
label variable unemp_v2 "Unemployment rate (alternative populism definition)"
label variable inflation_v2 "Inflation rate (alternative populism definition)"
label variable institutions_v2 "Quality of institutions (alternative populism definition)"
label variable presidential "1 if presidential system, 0 if parliamentary system"

order countryname country_id emerging presidential date year election_id ///
 party1 party_type1 partyname1 party2 party_type2 partyname2 ///
 cos_combo cos_multicult diff_combo diff_multicult leader pop pop_temp pop_vote_share gdp_pc unemp inflation institutions ///
 leader_v2 pop_v2 pop_temp_v2 pop_vote_share_v2 gdp_pc_v2 unemp_v2 inflation_v2 institutions_v2 

save "main_analysis_data.dta", replace







